package com.youyou.fusheng2.View.Adapter;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.youyou.fusheng2.Moudle.OnClick2;
import com.youyou.fusheng2.R;

import java.util.List;
import java.util.Map;

/**
 * @name fusheng2
 * @class name：com.youyou.fusheng2.View.Adapter
 * @anthor 浮生 QQ:2567294605
 * @time 2020/8/29 00:56
 * @to
 */
public class VdioUrlListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<Map<String, String>> Otherlist;
    private OnClick2 onClick;
    private int i;

    public VdioUrlListAdapter(List<Map<String, String>> otherlist, OnClick2 onClick, int i) {
        this.Otherlist = otherlist;
        this.onClick = onClick;
        this.i = i;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        @SuppressLint("InflateParams")
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.sousuo_item, parent, false);
        return new VdioUrlItem(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ((VdioUrlItem) holder).sousuoitem.setText(Otherlist.get(position).get("name"));

        ((VdioUrlItem) holder).sousuoitem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((VdioUrlItem) holder).sousuoitem.setTextColor(Color.DKGRAY);
                if (i == 0) {
                    ((VdioUrlItem) holder).sousuoitem.setGravity(Gravity.CENTER_VERTICAL);
                }
                onClick.listener1(0, String.valueOf(position), position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return (Otherlist == null || Otherlist.isEmpty()) ? 0 : (Otherlist.size());
    }

    private class VdioUrlItem extends RecyclerView.ViewHolder {

        private TextView sousuoitem;

        public VdioUrlItem(View inflate) {
            super(inflate);
            sousuoitem = inflate.findViewById(R.id.sousuoitem);
        }
    }
}
